package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.DashBoard;
import com.cskaoyan.mapper.MarketGoodsMapper;
import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.util.TransactionUtil;

public class DashboardServiceImpl implements DashboardService {
    @Override
    public BaseRespVo query() {
//        MarketUserExample example=new MarketUserExample();
//        MarketUserExample.Criteria criteria = example.createCriteria();
//        criteria.andIdEqualTo(id);
//        MarketUserMapper marketUserMapper = TransactionUtil.getMapper(MarketUserMapper.class);
//        List<MarketUser> marketUsers = marketUserMapper.selectByExample(example);
//        MarketUser marketUser = marketUsers.get(0);
        MarketUserExample example=new MarketUserExample();
        MarketUserExample.Criteria criteria = example.createCriteria();
        MarketUserMapper marketUserMapper = TransactionUtil.getMapper(MarketUserMapper.class);
        criteria.andIdIsNotNull();
        long userTotal = marketUserMapper.countByExample(example);

        MarketGoodsExample example1=new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria1 = example1.createCriteria();
        MarketGoodsMapper marketGoodsMapper = TransactionUtil.getMapper(MarketGoodsMapper.class);
        criteria1.andIdIsNotNull();
        long goodsTotal = marketGoodsMapper.countByExample(example1);

        MarketOrderExample example2 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria2 = example2.createCriteria();
        MarketOrderMapper marketOrderMapper=TransactionUtil.getMapper(MarketOrderMapper.class);
        criteria1.andIdIsNotNull();
        long marketOrder = marketOrderMapper.countByExample(example2);

        MarketGoodsProductExample example3 = new MarketGoodsProductExample();
        MarketGoodsProductExample.Criteria criteria3 = example3.createCriteria();
        MarketGoodsProductMapper marketGoodsProductMapper=TransactionUtil.getMapper(MarketGoodsProductMapper.class);
        criteria1.andIdIsNotNull();
        long marketProduct =marketGoodsProductMapper.countByExample(example3);

        DashBoard dashBoard = new DashBoard();
        dashBoard.setUserTotal(Math.toIntExact(userTotal));
        dashBoard.setGoodsTotal(Math.toIntExact(goodsTotal));
        dashBoard.setOrderTotal((int) marketOrder);
        dashBoard.setProductTotal((int) marketProduct);
        return BaseRespVo.ok(dashBoard);

    }
}
